<template>
	<div class="fankui w944">
		<alert ref="alert"></alert>
		<deleteAlert ref="deleteAlert"></deleteAlert>
		<div class="label_top">
			<p><i class="line"></i>意见反馈</p>
		</div>
		<div class="label_table">
			<el-table ref="multipleTable" :data="tableData" border @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="60"></el-table-column>
				<el-table-column prop="nickname" label="用户名" width="180"></el-table-column>
				<el-table-column prop="content" label="意见反馈"></el-table-column>
				<el-table-column label="操作" width="130">
					<template slot-scope="scope">
						<el-button @click="handleDelete(scope.row)" v-if="fankui.yjfk_del" class="red">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="fenyeMargin">
				<el-button @click="toggleSelection(tableData)" class="allSelect">全选</el-button>
				<el-button @click="handleDeleteAll" class="allDelete" v-if="fankui.yjfk_delAll">批量删除</el-button>
				<div class="pag_block">
					<el-pagination @current-change="handleCurrentChange" :current-page="currentpage" :page-size="pagesize" layout="prev, pager, next" :total="total"></el-pagination>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	import alert from '../../components/Alert.vue';
	import deleteAlert from '../../components/deleteAlert.vue';
	export default {
		data() {
			return {
				fankui:'',
				tableData: [],
				pagesize: 15,
				currentpage: 1,
				total: 1,
				multipleSelection: [],
				deleteType:'delete'
			}
		},
		methods: {
			getTableList(){
				this.$ajax({
					url: this.$root.jifuUrl + "/mns/feedback/feedbackList",
					headers:{'ContentType': 'application/json; charset=utf-8'},
					method: 'POST',
					data:{
						rootcompanyid:1,
						page :this.currentpage,
						num : this.pagesize
					},
					success: res => {
						if(res.data.code == 200) {
							this.tableData = res.data.data.list;
							this.total=res.data.data.pageParam.items;
						}
					}
				});
			},
			handleDelete(row){
				this.transitionRow = row;
				this.$rootFunction().rootDelete();
			},
			handleDeleteAll() {
				this.$rootFunction().rootDeleteAll();
			},
			deleteSubmit() {
				if(this.deleteType == 'delete'){
					var list = [];
					list.push({
						id:this.transitionRow.id
					});
					this.$ajax({ 
						url: this.$root.jifuUrl + "/mns/feedback/deleteFeedbackList",
						data:list,
						method: 'DELETE',
						headers:{'ContentType': 'application/json; charset=utf-8'},
						success: res => {
							if(res.data.code == 200) {
								this.$rootFunction().deleteResSuccess();
							}else{
								this.failText = res.data.message;
								this.$rootFunction().deleteResFail();
							}
						}
					});
				}else{
					this.$ajax({ 
						url: this.$root.jifuUrl + "/mns/feedback/deleteFeedbackList",
						data:this.multipleSelection,
						method: 'DELETE',
						headers:{'ContentType': 'application/json; charset=utf-8'},
						success: res => {
							if(res.data.code == 200) {
								this.$rootFunction().deleteResSuccess();
							}else{
								this.failText = res.data.message;
								this.$rootFunction().deleteResFail();
							}
						}
					});
				}
			},
			toggleSelection(rows) {
				if(rows) {
					rows.forEach(row => {
						this.$refs.multipleTable.toggleRowSelection(row, !this.allSelect)
					})
					this.allSelect = !this.allSelect;
				}
			},
			handleSelectionChange(val) {
				this.multipleSelection = [];
				for(var i = 0;i<val.length;i++){
					var s={id:val[i].id}
					this.multipleSelection.push(s)
				}
			},
		    handleCurrentChange (value) {
		        this.currentpage = value;
		        this.getTableList();
		    }
		},
		components: {
			alert,
			deleteAlert
		},
		mounted: function() {
			this.getTableList();
			this.fankui = this.$root.huasan.fankui;
		}
	}
</script>